package it.tcm.TeacherClassMate.util;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.naming.InitialContext;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;

import org.apache.log4j.Logger;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;

public class Util {
	
	private static Logger logger = Logger.getLogger("it.tcm.TeacherClassMate.util.Util");
	
	public static final String LIST_TYPOLOGY_BEAN = "listtypologybean";
	public static final String FORM_INSERT_EQUATION = "equationuploadform";
	public static final String FORM_INSERT_DISEQUATION = "disequationuploadform";
	public static final String FORM_GENERAL = "generalform";
	public static final String FORM_TEMPLATE = "templateform";
	public static final String SORT_TEMPLATE = "sortablesform";
	public static final String ORDERED_TEMPLATE = "orderedform";
	public static final String FORM_EQUATION_INSERTED = "equationinserted";
	public static final String FORM_DISEQUATION_INSERTED = "disequationinserted";
	public static final String ID_TYPOLOGY = "idtypology";
	public static final String ORDER_MAIN_OBJECT = "omb";
	
	public static final Integer EQUATIONS_TYPOLOGY = 1;
	public static final Integer DISEQUATIONS_TYPOLOGY = 2;
	public static final String EQUATION = "EQUATION";
	public static final String DISEQUATION = "DISEQUATION";
	public static final String EQUATION_PREFIX = "E";
	public static final String DISEQUATION_PREFIX = "D";
	
	public static final String SQL_OPERATOR_EQ = "eq";
	public static final String SQL_OPERATOR_LIKE = "like";
	public static final String SQL_OPERATOR_LIKE_UPPER = "likeupper";
	public static final String SQL_OPERATOR_GT = "gt";
	public static final String SQL_OPERATOR_LT = "lt";
	public static final String SQL_OPERATOR_GTE = "gte";
	public static final String SQL_OPERATOR_LTE = "lte";
	public static final String SQL_OPERATOR_IN = "in";
	
	public static final String SQL_TYPE_STRING = "typestring";
	public static final String SQL_TYPE_STRING_LIST = "typestringlist";
	public static final String SQL_TYPE_INTEGER = "typeinteger";
	public static final String SQL_TYPE_DATE = "typedate";
	
	public static final String DATE_FORMAT="dd/MM/yyyy";
	public static final String ORA_DATE_FORMAT="dd-MMM-yyyy";
	
	public static final String MAIL_SENDED = "mailsended";
	
	public static final Integer ADMINISTRATOR = 1;
	
	public static File bytesToFile(String filepath, byte[] bytes) {
		FileOutputStream out = null;
		File file = null;
		try { 
			 file  = new File(filepath);		
			if(!file.exists()){
				file.createNewFile();
			}
			out = new FileOutputStream(file);
	        out.write(bytes);  
	        out.close(); 
	    } catch (FileNotFoundException e) {
	    	logger.error("exception" + e.getMessage());
	    } catch (IOException e) {
	    	logger.error("exception" + e.getMessage());
	    } catch (Exception e)	{
	    	logger.error("exception" + e.getMessage());
	    }     
	    return file;		
	}
	
	
}
